package com.ecoolex.ying.space.core.manager;

import com.ecoolex.ying.space.core.dao.PaymentOrderRecordDAO;
import com.ecoolex.ying.space.entity.PaymentOrder;
import com.ecoolex.ying.space.entity.PaymentOrderRecord;
import com.ecoolex.ying.space.entity.PaymentOrderRecordExample;
import com.ecoolex.ying.space.enums.PaymentOrderRecordOperType;

import java.time.Instant;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PaymentOrderRecordManager {
	
    @Autowired
    private PaymentOrderRecordDAO dao;
    
    public PaymentOrderRecord create(PaymentOrder order,String paymentType, PaymentOrderRecordOperType operType) {
		PaymentOrderRecord record = new PaymentOrderRecord();
		record.setPaymentOrderId(order.getPaymentOrderId());
		record.setOperType(operType.real());
		record.setPaymentType(paymentType);
		return record;
	}

	public void add(PaymentOrderRecord record, String createUser) {
		record.setDeleted(PaymentOrderRecord.NOT_DELETED);
		record.setCreateUser(createUser);
		record.setCreateTime(Date.from(Instant.now()));
		record.setUpdateUser(createUser);
		record.setUpdateTime(Date.from(Instant.now()));
		dao.insert(record);
	}
	
	public List<PaymentOrderRecord> queryByOrderId(Integer paymentOrderId) {
		PaymentOrderRecordExample example = new PaymentOrderRecordExample();
		example.createCriteria().andPaymentOrderIdEqualTo(paymentOrderId);
		return dao.selectByExample(example);
	}
}